package databasetranslation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.sql.SQLException;

import org.junit.Test;

import database.MySQLServer;
import database.SQLServer;

/**
 * Tests the client list with a SQL server.
 * 
 * @author Barry
 *
 */
public class testSubscriptionList extends testSubscriptionList_NoDB {
	
	@Override
	protected SQLServer buildServer() {
		return new MySQLServer("localhost","root","usbw");
	}
	
	@Test
	public void testGetEntry() throws SQLException {
		list.add(subscription1);
		list.add(subscription2);
		assertEquals(subscription2, list.getEntry(subscription2.getId()));
	}
	
	@Test(expected=RuntimeException.class)
	public void testGetEntry_error() throws SQLException {
		list.add(subscription2);
		list.getEntry(273);
	}
	
	@Test
	public void testImportList() throws SQLException {
		list.add(subscription1);
		list.add(subscription2);
		
		newList.importList();
		assertEquals(list.getSubscriptions(), newList.getSubscriptions());
	}
	
	@Test
	public void test_isEqualToDatabase() throws SQLException {
		list.add(subscription1);
		list.add(subscription2);
		assertTrue(list.isEqualToDatabase());
		
		// Change externally
		newList.delete(subscription2);
		// No longer equal
		assertFalse(list.isEqualToDatabase());
	}

	@Test
	public void testTruncate() throws SQLException {
		list.add(subscription2);
		list.clearDatabaseTable();
		list.importList();
		assertEquals(true,list.getSubscriptions().isEmpty());
	}
	
}